package com.nantai.jiafang.nantaijiafang.ViewModel;

import android.content.Context;
import android.util.Log;

import com.nantai.jiafang.nantaijiafang.HttpNet.HttpClient;
import com.nantai.jiafang.nantaijiafang.IConstant;
import com.nantai.jiafang.nantaijiafang.bean.ZhiJjian.AllDefects;
import com.nantai.jiafang.nantaijiafang.bean.ZhiJjian.ColourInfo;
import com.nantai.jiafang.nantaijiafang.bean.ZhiJjian.GroupInfo;
import com.nantai.jiafang.nantaijiafang.bean.ZhiJjian.HeTongHao;
import com.nantai.jiafang.nantaijiafang.bean.ZhiJjian.InsDefect;
import com.nantai.jiafang.nantaijiafang.bean.ZhiJjian.MLBodyItem;
import com.nantai.jiafang.nantaijiafang.bean.ZhiJjian.MLHeardItem;
import com.nantai.jiafang.nantaijiafang.bean.ZhiJjian.ProductInfo;
import com.nantai.jiafang.nantaijiafang.bean.ZhiJjian.PurchaseInfo;
import com.nantai.jiafang.nantaijiafang.bean.ZhiJjian.QuiltDefects;
import com.nantai.jiafang.nantaijiafang.bean.ZhiJjian.ReasonRemark;
import com.nantai.jiafang.nantaijiafang.bean.ZhiJjian.SewingDataRes;
import com.nantai.jiafang.nantaijiafang.bean.ZhiJjian.SewingDetail;
import com.nantai.jiafang.nantaijiafang.bean.ZhiJjian.StaffInfo;
import com.nantai.jiafang.nantaijiafang.bean.ZhiJjian.Tip;
import com.nantai.jiafang.nantaijiafang.nt5s.Http.Error;
import com.nantai.jiafang.nantaijiafang.nt5s.Http.ResponseHandler;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.security.auth.login.LoginException;

import retrofit2.Call;

import static com.bumptech.glide.gifdecoder.GifHeaderParser.TAG;

/**
 * Created by Administrator on 2017/11/9.
 */

public class Zhijian_Net {
    public interface GetDoubleData<T>{
        void success(T s);
        void success2(T s);
    }
    public interface GetSingData<T>{
        void success(T s);
    }
    //获取合同号和面料名称
    public static  void gethetonghao(Context context,GetDoubleData getDoubleData) {
        HttpClient httpClient=new HttpClient(context);
        Call<List<HeTongHao>> call=httpClient.service(IConstant.NT_ZHIJIAN).gethetonghao();
        String ss=call.request().url().toString();
        httpClient.request(call ,new ResponseHandler(){
            @Override
            public void onSuccess(Object o) {
                List<HeTongHao> heTongHaos=(List<HeTongHao>)o;
                ArrayList<String> listt=new ArrayList<>();
                for (HeTongHao heTongHao:
                        heTongHaos) {
                    listt.add(heTongHao.getValue());
                }
                getDoubleData.success(listt);
            }

            @Override
            public void onFailure(int code, Error e) {

            }
        });
        Call call2=httpClient.service(IConstant.NT_ZHIJIAN).getMianLiaoName();
        httpClient.request(call2, new ResponseHandler() {
            @Override
            public void onSuccess(Object o) {
                List<HeTongHao> heTongHaos=(List<HeTongHao>)o;

                getDoubleData.success2(heTongHaos);
            }
            @Override
            public void onFailure(int code, Error e) {

            }
        });
    }
    //面料外检表头列表显示  查询
    public static  void getHeardItem(Context context, Map<String,String> map,GetSingData getSingData) {
        HttpClient httpClient=new HttpClient(context);
        Call<MLHeardItem> call=httpClient.service(IConstant.NT_ZHIJIAN).getHeardItem(map);
        String ss=call.request().url().toString();
        Log.e(TAG, "getHeardItem: "+call.request().url());
        httpClient.request(call, new ResponseHandler() {
            @Override
            public void onSuccess(Object o) {
                MLHeardItem mlHeardItemList=(MLHeardItem )o;
                getSingData.success(mlHeardItemList);
            }
            @Override
            public void onFailure(int code, Error e) {
                Log.e(TAG, "onFailure: "+e.getMessage() );
            }
        });
    }
    //面料外检表体列表显示
    public  static  void getHeardBody(Context context, Map<String,String> map,GetSingData getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call call=httpClient.service(IConstant.NT_ZHIJIAN).getBodyItem(map);
        httpClient.request(call, new ResponseHandler() {
            @Override
            public void onSuccess(Object o) {
                 List<MLBodyItem> mlBodyItems=( List<MLBodyItem> )o;
                getSingData.success(mlBodyItems);
            }
            @Override
            public void onFailure(int code, Error e) {
                Log.e(TAG, "onFailure: "+e.getMessage() );
            }
        });
    }

    //获取生产厂商
    public  static  void gethetonghao2(Context context,GetSingData<List<HeTongHao>> getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call call=httpClient.service(IConstant.NT_ZHIJIAN).getSupplierInfo();
        httpClient.request(call ,new ResponseHandler(){
            @Override
            public void onSuccess(Object o) {
                List<HeTongHao> heTongHaos=(List<HeTongHao>)o;
                getSingData.success(heTongHaos);
            }

            @Override
            public void onFailure(int code, Error e) {

            }
        });
    }

    //获取工程师
    public  static  void getEngineerInfo(Context context,GetSingData<List<HeTongHao>> getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call call=httpClient.service(IConstant.NT_ZHIJIAN).getEngineerInfo();
        httpClient.request(call ,new ResponseHandler(){
            @Override
            public void onSuccess(Object o) {
                List<HeTongHao> heTongHaos=(List<HeTongHao>)o;
                getSingData.success(heTongHaos);
            }

            @Override
            public void onFailure(int code, Error e) {

            }
        });
    }
    //根据合同号获取采购订单信息
    public  static  void getPurchaseInfo(Context context, Map<String,String> map,GetSingData getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call call=httpClient.service(IConstant.NT_ZHIJIAN).getOrderInfo(map);
        Log.e(TAG, "getPurchaseInfo: "+call.request().url());
        httpClient.request(call, new ResponseHandler() {
            @Override
            public void onSuccess(Object o) {
                PurchaseInfo purchaseInfo=(PurchaseInfo )o;

                getSingData.success(purchaseInfo);
            }
            @Override
            public void onFailure(int code, Error e) {
                Log.e(TAG, "onFailure: "+e.getMessage() );
            }
        });
    }
    //面料检验获取所有疵点
    public  static  void getAllDefects(Context context,GetSingData<List<AllDefects>> getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call call=httpClient.service(IConstant.NT_ZHIJIAN).getAllDefects();
        Log.e(TAG,"zhijianzidian:"+call.request().url());
        httpClient.request(call ,new ResponseHandler(){
            @Override
            public void onSuccess(Object o) {
                List<AllDefects> allDefects=(List<AllDefects>)o;
                ArrayList<AllDefects> listt=new ArrayList<>();
//                for (HeTongHao heTongHao:heTongHaos) {
//                    listt.add(heTongHao.getValue());
//                }
                getSingData.success(allDefects);
            }

            @Override
            public void onFailure(int code, Error e) {

            }
        });
    }

    //获取所有疵点
    public  static  void getAllQuiltDefects(Context context, GetSingData<List<QuiltDefects>> getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call call=httpClient.service(IConstant.NT_ZHIJIAN).getAllQuiltDefect();
        httpClient.request(call ,new ResponseHandler(){
            @Override
            public void onSuccess(Object o) {
                List<QuiltDefects> allDefects=(List<QuiltDefects>)o;
                getSingData.success(allDefects);
            }

            @Override
            public void onFailure(int code, Error e) {

            }
        });
    }


    //获取原因
    public  static  void getReasonRemark(Context context,Map<String,String> map,GetSingData<List<ReasonRemark>> getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call call=httpClient.service(IConstant.NT_ZHIJIAN).getReasonRemark(map);
        httpClient.request(call ,new ResponseHandler(){
            @Override
            public void onSuccess(Object o) {
                List<ReasonRemark> allDefects=(List<ReasonRemark>)o;
              /*  for (HeTongHao heTongHao:
                        heTongHaos) {
                    listt.add(heTongHao.getValue());
                }*/
                getSingData.success(allDefects);
            }

            @Override
            public void onFailure(int code, Error e) {

            }
        });
    }

    //新增/修改表头信息
    public  static  void saveEInspectHead(Context context, Map<String,String> map,GetSingData<List<Tip>> getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call call=httpClient.service(IConstant.NT_ZHIJIAN).saveEInspecthead(map);
        Log.e(TAG, "saveEInspectHead: "+call.request().url());
        httpClient.request(call, new ResponseHandler() {
            @Override
            public void onSuccess(Object o) {
                List<Tip> purchaseInfo=(List<Tip>)o;
                getSingData.success(purchaseInfo);
            }
            @Override
            public void onFailure(int code, Error e) {
                Log.e(TAG, "onFailure: "+e.getMessage() );
            }
        });
    }

    //审核/取消审核
    public  static  void opApprove(Context context, Map<String,String> map,GetSingData<List<Tip>> getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call call=httpClient.service(IConstant.NT_ZHIJIAN).opApprove(map);
        Log.e(TAG, "opApprove: "+call.request().url());
        httpClient.request(call, new ResponseHandler() {
            @Override
            public void onSuccess(Object o) {
                List<Tip> purchaseInfo=(List<Tip>)o;
                getSingData.success(purchaseInfo);
            }
            @Override
            public void onFailure(int code, Error e) {
                Log.e(TAG, "onFailure: "+e.getMessage() );
            }
        });
    }

    //删除表头/表体
    public  static  void batchDeletehead(Context context, Map<String,String> map,GetSingData<List<Tip>> getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call call=httpClient.service(IConstant.NT_ZHIJIAN).batchDeletehead(map);
        Log.e(TAG, "batchDeleteDetail: "+call.request().url());
        httpClient.request(call, new ResponseHandler() {
            @Override
            public void onSuccess(Object o) {
                List<Tip> purchaseInfo=(List<Tip>)o;
                getSingData.success(purchaseInfo);
            }
            @Override
            public void onFailure(int code, Error e) {
                Log.e(TAG, "onFailure: "+e.getMessage() );
            }
        });
    }

    //准入
    public  static  void admitPass(Context context, Map<String,String> map,GetSingData<List<Tip>> getSingData){
        map.put("opType","admitPass");
        map.put("Type","准入");
        HttpClient httpClient=new HttpClient(context);
        Call call=httpClient.service(IConstant.NT_ZHIJIAN).admitPass(map);
        Log.e(TAG, "admitPass: "+call.request().url());
        httpClient.request(call, new ResponseHandler() {
            @Override
            public void onSuccess(Object o) {
                List<Tip> purchaseInfo=(List<Tip>)o;
                getSingData.success(purchaseInfo);
            }
            @Override
            public void onFailure(int code, Error e) {
                Log.e(TAG, "onFailure: "+e.getMessage() );
            }
        });
    }

    //重新检验
    public  static  void reCheck(Context context, Map<String,String> map,GetSingData<List<Tip>> getSingData){
        map.put("opType","reCheck");
        map.put("Type","重新检验");
        HttpClient httpClient=new HttpClient(context);
        Call call=httpClient.service(IConstant.NT_ZHIJIAN).reCheck(map);
        Log.e(TAG, "reCheck: "+call.request().url());
        httpClient.request(call, new ResponseHandler() {
            @Override
            public void onSuccess(Object o) {
                List<Tip> purchaseInfo=(List<Tip>)o;
                getSingData.success(purchaseInfo);
            }
            @Override
            public void onFailure(int code, Error e) {
                Log.e(TAG, "onFailure: "+e.getMessage() );
            }
        });
    }


    //质检绗缝/裁剪巡检



    //获取绗缝巡检表头
    public  static  void getQuiltInsHead(Context context, Map<String,String> map,GetSingData getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call<SewingDataRes> call=httpClient.service(IConstant.NT_ZHIJIAN).getQuiltInsHead(map);
        Log.e(TAG, "getQuiltInsHead: "+call.request().url());
        httpClient.request(call, new ResponseHandler() {
            @Override
            public void onSuccess(Object o) {
                SewingDataRes sewingDataRes=(SewingDataRes )o;
                getSingData.success(sewingDataRes);
            }
            @Override
            public void onFailure(int code, Error e) {
                Log.e(TAG, "onFailure: "+e.getMessage() );
            }
        });
    }

    //获取裁剪内检表头
    public  static  void getCutInsHead(Context context, Map<String,String> map,GetSingData getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call<SewingDataRes> call=httpClient.service(IConstant.NT_ZHIJIAN).getCutInsHead(map);
        Log.e(TAG, "getCutInsHead: "+call.request().url());
        httpClient.request(call, new ResponseHandler() {
            @Override
            public void onSuccess(Object o) {
                SewingDataRes sewingDataRes=(SewingDataRes )o;
                getSingData.success(sewingDataRes);
            }
            @Override
            public void onFailure(int code, Error e) {
                Log.e(TAG, "onFailure: "+e.getMessage() );
            }
        });
    }



    //获取成品名称(下拉数据源，可按输入内容从下拉列表中筛选)
    public  static  void getProductInfo(Context context,GetSingData<List<ProductInfo>> getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call call=httpClient.service(IConstant.NT_ZHIJIAN).getAllProductInfo();
        Log.e(TAG, "getProductInfo: "+call.request().url());
        httpClient.request(call ,new ResponseHandler(){
            @Override
            public void onSuccess(Object o) {
                List<ProductInfo> heTongHaos=(List<ProductInfo>)o;
                getSingData.success(heTongHaos);
            }

            @Override
            public void onFailure(int code, Error e) {

            }
        });
    }

    //根据选中的成品获取成品颜色
    public static  void getAllColorByPro(Context context,GetSingData<List<ColourInfo>> getSingData){
        HttpClient httpClient = new HttpClient(context);
        Call call = httpClient.service(IConstant.NT_ZHIJIAN).getAllColorByPro();
        Log.e(TAG, "getAllColorByPro: "+call.request().url() );
        httpClient.request(call, new ResponseHandler() {
            @Override
            public void onSuccess(Object o) {
                List<ColourInfo> heTongHaos=(List<ColourInfo>)o;
                getSingData.success(heTongHaos);
            }

            @Override
            public void onFailure(int code, Error e) {
                Log.e(TAG, "onFailure: "+e.getMessage() );
            }
        });

    }

    //获取所有生产组别
    public  static  void getAllGroupInfo(Context context,GetSingData<List<GroupInfo>> getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call call=httpClient.service(IConstant.NT_ZHIJIAN).getAllGroupInfo();
        Log.e(TAG, "getAllGroupInfo: "+call.request().url() );
        httpClient.request(call ,new ResponseHandler(){
            @Override
            public void onSuccess(Object o) {
                List<GroupInfo> heTongHaos=(List<GroupInfo>)o;
                getSingData.success(heTongHaos);

            }

            @Override
            public void onFailure(int code, Error e) {

            }
        });
    }

    //根据组别获取产品信息
    public  static  void getProducerByGroup(Context context, Map<String,String> map,GetSingData<List<StaffInfo>> getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call call=httpClient.service(IConstant.NT_ZHIJIAN).getProducerByGroup(map);
        Log.e(TAG, "getProducerByGroup: "+call.request().url());
        httpClient.request(call, new ResponseHandler() {
            @Override
            public void onSuccess(Object o) {
                List<StaffInfo> purchaseInfo=(List<StaffInfo>)o;
                getSingData.success(purchaseInfo);
            }
            @Override
            public void onFailure(int code, Error e) {
                Log.e(TAG, "onFailure: "+e.getMessage() );
            }
        });
    }

    //保存绗缝内检数据




        //删除绗缝内检数据
        public  static  void deleteQuiltHead(Context context, Map<String,String> map,GetSingData<List<Tip>> getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call<List<Tip>> call=httpClient.service(IConstant.NT_ZHIJIAN).deleteQuiltHead(map);
        Log.e(TAG, "deleteQuiltHead: "+call.request().url());
        httpClient.request(call, new ResponseHandler() {
            @Override
            public void onSuccess(Object o) {
                List<Tip> purchaseInfo=(List<Tip>)o;
                getSingData.success(purchaseInfo);
            }
            @Override
            public void onFailure(int code, Error e) {
                Log.e(TAG, "onFailure: "+e.getMessage() );
            }
        });
    }

    //绗缝获取所有疵点
    public  static  void getInsDefect(Context context,GetSingData<List<InsDefect>> getSingData){
        HttpClient httpClient=new HttpClient(context);
        Call call=httpClient.service(IConstant.NT_ZHIJIAN).getInsDefect();
        Log.e(TAG,"绗缝获取所有疵点:"+call.request().url());
        httpClient.request(call ,new ResponseHandler(){
            @Override
            public void onSuccess(Object o) {
                List<InsDefect> insDefect=(List<InsDefect>)o;
                ArrayList<InsDefect> listt=new ArrayList<InsDefect>();
//                for (HeTongHao heTongHao:heTongHaos) {
//                    listt.add(heTongHao.getValue());
//                }
                getSingData.success(insDefect);
            }

            @Override
            public void onFailure(int code, Error e) {

            }
        });
    }
}
